package org.example.writable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, Text, FlowBean> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, FlowBean>.Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] split = line.split(" ");
        String phone = split[1];
        String up = split[split.length - 3];
        String down = split[split.length - 2];

        Text text = new Text();
        text.set(phone);
        FlowBean flowBean = new FlowBean();
        flowBean.setUpFlow(Long.parseLong(up));
        flowBean.setDownFlow(Long.parseLong(down));
        flowBean.setSumFlow();

        context.write(text, flowBean);
    }
}

